import { createRouter, createWebHistory } from 'vue-router'

const routes = [
    {
        path: '/login',
        component: () => import('@/views/SystemLogin.vue')
    },
    {
        path: '/',
        redirect: '/work-order-list',
        meta: { requiresAuth: true },  //这个路由需要用户登录后才能访问
        children: [
            {
                path: 'work-order-list',
                component: () => import('@/views/WorkOrderList.vue')
            },
            {
                path: 'work-order-initiate',
                component: () => import('@/views/WorkOrderInitiate.vue')
            },
            {
                path: 'work-order-distribute',
                component: () => import('@/views/WorkOrderDistribute.vue')
            },
            {
                path: 'work-order-accept',
                component: () => import('@/views/WorkOrderAccept.vue')
            },
            {
                path: 'work-order-reply',
                component: () => import('@/views/WorkOrderReply.vue')
            },
            {
                path: 'work-order-internal-forward',
                component: () => import('@/views/WorkOrderInternalForward.vue')
            },
            {
                path: 'work-order-file',
                component: () => import('@/views/WorkOrderFile.vue')
            },
            {
                path: 'work-order-cancel',
                component: () => import('@/views/WorkOrderCancel.vue')
            },
            {
                path: 'notification-management',
                component: () => import('@/views/NotificationManagement.vue')
            },
            {
                path: 'data-dashboard',
                component: () => import('@/views/DataDashboard.vue')
            },
            {
                path: 'efficiency-analysis',
                component: () => import('@/views/EfficiencyAnalysis.vue')
            },
            {
                path: 'equipment-management',
                component: () => import('@/views/EquipmentManagement.vue')
            },
            {
                path: 'material-management',
                component: () => import('@/views/MaterialManagement.vue')
            },
            {
                path: 'parts-management',
                component: () => import('@/views/PartsManagement.vue')
            },
            {
                path: 'purchase-management',
                component: () => import('@/views/PurchaseManagement.vue')
            },
            {
                path: 'scrap-management',
                component: () => import('@/views/ScrapManagement.vue')
            },
            {
                path: 'maintenance-plan',
                component: () => import('@/views/MaintenancePlan.vue')
            },
            {
                path: 'maintenance-records',
                component: () => import('@/views/MainrenanceRecords.vue')
            },
            {
                path: 'dashboard-container',
                component: () => import('@/views/DashboardContainer.vue')
            }
        ]
    }
]

const router = createRouter({
    history: createWebHistory(),
    routes
})

// 路由守卫
// router.beforeEach((to, from, next) => {
//     const isAuthenticated = localStorage.getItem('token')
//
//     if (to.meta.requiresAuth && !isAuthenticated) {
//         next('/login')
//     } else if (to.meta.roles) {
//         const userRole = store.state.auth.user.role
//         if (to.meta.roles.includes(userRole)) {
//             next()
//         } else {
//             next('/403') // 无权限页面
//         }
//     } else {
//         next()
//     }
// })

export default router